package com.xajh.duoduo.environment;


import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;

import java.awt.*;

/**
 * 全局唯一id：prex#nameSpace#group#账号#roleNum#区服
 * prex:游戏名
 * nameSpace:机器
 * group:任务 (具体任务设置)
 * account:账号 (切换账号时设置)
 * roleNum:当前账号下第几个角色(切换角色时设置)
 * area:游戏区服 (切换账号时设置)
 */
public class Environment {

    private ApplicationContext applicationContext;

    private final String PREX = "xajh";

    private final String NAME_SPACE = "first";

    private String account;

    private String area;

    private String roleNum;

    private Environment() {
    }

    /* 此处使用一个内部类来维护单例 */
    private static class EnvironmentFactory{
        private static Environment instance = new Environment();
    }

    /* 获取实例 */
    public static Environment getInstance(){
        return EnvironmentFactory.instance;
    }

    /* 如果该对象被用于序列化，可以保证对象在序列化前后保持一致 */
    public Object readResolve() {
        return getInstance();
    }

    public  <T> T getBean(String name, Class<T> aClass) {
        return applicationContext.getBean(name, aClass);
    }

    public String getPREX() {
        return PREX;
    }

    public String getNAME_SPACE() {
        return NAME_SPACE;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getRoleNum() {
        return roleNum;
    }

    public void setRoleNum(String roleNum) {
        this.roleNum = roleNum;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
